
var express = require('express');
var fs = require('fs');
var app = express();

app.use(express.bodyParser());
app.listen(3339, "127.0.0.1", function() {
	console.log("Server Start.");
});

app.get("/", function(req, res) {
	fs.readFile('index.html', function(error, data) {
		res.writeHead(200, {'content-type': 'text/html'});
		res.end(data, function(error) {
			console.log(error);
		});
	});
});

app.post('/upload', function(req, res) {
	fs.readFile(req.files.uploadFile.path, function(error, data) {
		var filePath = __dirname+"\\files\\" + req.files.uploadFile.name;
		fs.writeFile(filePath, data, function(error) {
			if(error) {
				throw err;
			}
			else
			{
				//res.redirect("back");
				res.send(filePath)
			}
		});
	});
});